﻿using System.Configuration;
using AutomatedAcceptanceTests.Enums;
using AutomatedAcceptanceTests.Extensions;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;

namespace AutomatedAcceptanceTests.Infrastructure
{
    public class WebDriverFactory
    {
        private static IWebDriver _webDriver;

        public static IWebDriver GetWebDriver()
        {
            var webDriver = ConfigurationManager.AppSettings["WebDriver"];
            WebDriverType webDriverType = WebDriverType.FireFox;
            webDriverType = webDriverType.GetWebDriverType(webDriver);

            switch (webDriverType)
            {
                case WebDriverType.FireFox:
                    return _webDriver ?? (_webDriver = new FirefoxDriver());
                    break;

                case WebDriverType.Chrome:
                    return _webDriver ?? (_webDriver = new ChromeDriver(@ConfigurationManager.AppSettings["ChromeWebDriverLocation"]));
                    break;

                case WebDriverType.IE:
                    return _webDriver ?? new InternetExplorerDriver(@ConfigurationManager.AppSettings["IEWebDriverLocation"]);
                    break;

                default:
                    return _webDriver ?? (_webDriver = new FirefoxDriver());
                    break;
            }
        }

        public static void SetWebDriver(IWebDriver webDriver)
        {
            _webDriver = webDriver;
        }

    }
}